<#assign className = table.className>   
<#assign classNameLower = className?uncap_first> 
<#assign primaryKeyColumn = table.primaryKeyColumn>
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${basepackage}.mapper.${className}Mapper" >
  <!--
    - =======================================================
 	- ${className}对象
 	- @author yanwl
 	- @date ${.now?string("yyyy-MM-dd hh:mm:ss")}
 	- ======================================================= 
  -->
  <resultMap id="BaseResultMap" type="${className}" >
    <#list table.columns as column>
    <#if column.unique && column.pk>
    <id column="${column.sqlName}" property="${column.columnName}" jdbcType="${column.jdbcType}" />
    <#else>
    <result column="${column.sqlName}" property="${column.columnName}" jdbcType="${column.jdbcType}" />
    </#if>
    </#list>
  </resultMap>
  
  <!--
    - =======================================================
 	- 基本列
 	- @author yanwl
 	- @date ${.now?string("yyyy-MM-dd hh:mm:ss")}
 	- ======================================================= 
  -->
  <sql id="Base_Column_List" >
    <#list table.columns as column>
    ${column.sqlName} <#if column_has_next>,</#if>
    </#list>
  </sql>
  
  <!--
    - =======================================================
 	- 根据主键查询${className}对象
 	- @author yanwl
 	- @date ${.now?string("yyyy-MM-dd hh:mm:ss")}
 	- ======================================================= 
  -->
  <select id="select${className}ByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.${primaryKeyColumn.javaType}" >
    select 
    <include refid="Base_Column_List" />
    from ${table.sqlName}
    where ${primaryKeyColumn.sqlName} = ${r"#{"}${primaryKeyColumn.columnName},jdbcType=${primaryKeyColumn.jdbcType}${r"}"}
  </select>
  
  <!--
    - =======================================================
 	- 查询所有的${className}对象
 	- @author yanwl
 	- @date ${.now?string("yyyy-MM-dd hh:mm:ss")}
 	- ======================================================= 
  -->
  <select id="selectAll${className}s" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from ${table.sqlName}
  </select>
  
  <!--
    - =======================================================
 	- 查询${className}对象总数
 	- @author yanwl
 	- @date ${.now?string("yyyy-MM-dd hh:mm:ss")}
 	- ======================================================= 
  -->
  <select id="select${className}TotalRows" resultType="java.lang.Integer">
    select count(*) from ${table.sqlName}
  </select>
  
  <!--
    - =======================================================
 	- 删除${className}对象
 	- @author yanwl
 	- @date ${.now?string("yyyy-MM-dd hh:mm:ss")}
 	- ======================================================= 
  -->
  <delete id="delete${className}" parameterType="java.lang.${primaryKeyColumn.javaType}" >
    delete from ${table.sqlName}
    where ${primaryKeyColumn.sqlName} = ${r"#{"}${primaryKeyColumn.columnName},jdbcType=${primaryKeyColumn.jdbcType}${r"}"}
  </delete>
  
  <!--
    - =======================================================
 	- 新增${className}对象
 	- @author yanwl
 	- @date ${.now?string("yyyy-MM-dd hh:mm:ss")}
 	- ======================================================= 
  -->
  <insert id="insert${className}" parameterType="${className}" keyProperty="${primaryKeyColumn.columnName}" useGeneratedKeys="true">
    insert into ${table.sqlName}
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <#list table.columns as column>
      <if test="${column.columnName} != null" >
       	${column.sqlName},
      </if>
      </#list>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <#list table.columns as column>
      <if test="${column.columnName} != null" >
       	${r"#{"}${column.columnName},jdbcType=${column.jdbcType}${r"}"},
      </if>
      </#list>
    </trim>
  </insert>
  
  <!--
    - =======================================================
 	- 更新${className}对象
 	- @author yanwl
 	- @date ${.now?string("yyyy-MM-dd hh:mm:ss")}
 	- ======================================================= 
  -->
  <update id="update${className}" parameterType="${className}" >
    update ${table.sqlName} set 
    <#list table.columns as column>
    <#if !column.unique && !column.pk >
    ${column.sqlName} = ${r"#{"}${column.columnName},jdbcType=${column.jdbcType}${r"}"} <#if column_has_next>,</#if>
    </#if>
    </#list>
    where ${primaryKeyColumn.sqlName} = ${r"#{"}${primaryKeyColumn.columnName},jdbcType=${primaryKeyColumn.jdbcType}${r"}"}
  </update>
</mapper>